package com.jf.anmocker.plugin.asmfactory

import com.jf.anmocker.plugin.mockcore.asm.AnMockerAnoVisitor
import com.jf.mocker.anotations.IClassMocker
import org.objectweb.asm.*

/**
 * @Class: MyScanClassVisitor
 * @Description:
 * @author:
 * @Date: 2022/9/21
 */
class AMScanClassVisitor(nextVisitor : ClassVisitor) : ClassVisitor(Opcodes.ASM6, nextVisitor) {

    private var clzAnoTarget : Any? = null

    override fun visit(
        version: Int,
        access: Int,
        name: String?,
        signature: String?,
        superName: String?,
        interfaces: Array<out String>?
    ) {
        super.visit(version, access, name, signature, superName, interfaces)
    }

    override fun visitAnnotation(descriptor: String?, visible: Boolean): AnnotationVisitor {
        //println("visitAnnotation descriptor = $descriptor")
        return if(Type.getDescriptor(IClassMocker::class.java).equals(descriptor)){
            val clzAnoVisitor = AnMockerAnoVisitor(super.visitAnnotation(descriptor, visible))
            clzAnoTarget = clzAnoVisitor.getAnoValue()
            return clzAnoVisitor
        }else{
            super.visitAnnotation(descriptor, visible)
        }
    }
}

